class Solution(object):
    def findComplement(self, num):
        """
        :type num: int
        :rtype: int
        """
        t = 30
        while t >= 0:
            if num >> t & 1 > 0:
                break
            else:
                t -= 1
        return ~num & (2 ** (t + 1) - 1)
